﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace Vulcano.Helpers
{
    
    public class FuzzyDateTime
    {
        private readonly IList<IDateTimeParser> _parsers;

        public FuzzyDateTime()
        {
        }

        public FuzzyDateTime(IList<IDateTimeParser> parsers)
        {
            _parsers = parsers;
        }
        


        public DateTime Parse(string pattern)
        {
            var result = DateTime.MinValue;
            
            foreach (var parser in _parsers)
            {
                
                var m = parser.Regex().Match(pattern);
                
                if (m.Success)
                {
                    result = parser.Parse(m);
                    if(result!= DateTime.MinValue)
                    {
                        break;
                    }
                }
                
                
            }
            return result;
        }
        
    }
    
    

}
